package com.claimSettlement.controller;

import com.claimSettlement.pojo.Case;
import com.claimSettlement.pojo.Worker;
import com.claimSettlement.service.CaseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/case")
public class CaseController {

    @Autowired
    CaseService service;
    @RequestMapping("/getCaseAll")
    public PageInfo<Case> getCaseAll(int page){
        PageHelper.startPage(page,4);
        List<Case> list=service.getCaseAll();
        PageInfo<Case> pageInfo = new PageInfo<Case>(list,4);
        return pageInfo;
    }

    @RequestMapping(value = "/insertCase",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public int insertCase(@RequestBody Case cases){
        int count=service.insertCase(cases);
        return count;
    }

    @RequestMapping("/updCaseHandling")
    public int updCaseHandling(int caseHandling,int caseState,String caseId) {
        return service.updCaseHandling(caseHandling,caseState, caseId);
    }

    @RequestMapping("/insertWorker")
    public int insertWorker(String caseId,int userId,String dispatchedWorkerEndTime) {
        return service.insertWorker(caseId, userId,dispatchedWorkerEndTime);
    }

    @RequestMapping("/getCaseByUserId")
    public PageInfo<Case> getCaseByUserId(int userId,int shuzhi,int inbh,int endtime,int page) {
        PageHelper.startPage(page,4);
        List<Case> list = service.getCaseByUserId(userId,shuzhi,inbh,endtime);
        PageInfo<Case> pageInfo = new PageInfo<Case>(list);
        return pageInfo;
    }

    @RequestMapping("/getCaseBycaseId")
    public Case getCaseBycaseId(String caseId){
        return service.getCaseBycaseId(caseId);
    }

    @RequestMapping("/getCaseOne")
    public Case getCaseOne(String caseId) {
        return service.getCaseOne(caseId);
    }

    @RequestMapping("/getCaseId")
    public PageInfo<Case> getCaseId(String caseId, String recognizeeName, String plateNumber,int page) {
        PageHelper.startPage(page,4);
        List<Case> list=service.getCaseId(caseId, recognizeeName, plateNumber);
        PageInfo<Case> pageInfo = new PageInfo<Case>(list,4);
        return pageInfo;
    }

    @RequestMapping(value = "/updateCase",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public int updateCase(@RequestBody Case cases) {
        return service.updateCase(cases);
    }

    @RequestMapping("/getCaseChul")
    public PageInfo<Case> getCaseChul(int page){
        PageHelper.startPage(page,4);
        List<Case> list=service.getCaseChul();
        PageInfo<Case> pageInfo = new PageInfo<Case>(list,4);
        return pageInfo;
    }
    @RequestMapping("/getWorkerAll")
    public List<Worker> getWorkerAll(){
        return service.getWorkerAll();
    }

    @RequestMapping("/getSurveyCountCaseId")
    public String getSurveyCountCaseId(String caseId) {
        return service.getSurveyCountCaseId(caseId) > 0 ? "存在" : "不存在";
    }

    @RequestMapping("/getCaseCount")
    public int getCaseCount(String recognizeeId, String plateNumber) {
        return service.getCaseCount(recognizeeId, plateNumber);
    }
}
